package porridgenpickle.server;

import porridgenpickle.client.VideoService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.googlecode.objectify.ObjectifyService;

import static com.googlecode.objectify.ObjectifyService.ofy;

public class VideoServiceImpl extends RemoteServiceServlet implements VideoService {
		
	private static final long serialVersionUID = 1L;
	
	static {
		ObjectifyService.factory().register(VideoEntity.class);
	}

	@Override
	public String getHtml() {				
										
		VideoEntity entity = ofy().load().type(VideoEntity.class).first().get();
		
		if (null == entity)
			return "Error - No video found";
		
		return entity.html;
	}
	
	public void setVideoHtml(String html) {
		VideoEntity entity = ofy().load().type(VideoEntity.class).first().get();
		
		if (null == entity)
			entity = new VideoEntity();
		
		entity.html = html;
		ofy().save().entity(entity).now();
	}
}
